var map;
var infoBoxTemp = null;

$(function () {
    // var whdef = 100/1920;// 表示1920的设计图,使用100PX的默认值
    var whdef = 100/916;// 表示1920的设计图,使用100PX的默认值
    var wH = window.innerHeight;// 当前窗口的高度
    var wW = window.innerWidth;// 当前窗口的宽度
    // var rem = wW * whdef;// 以默认比例值乘以当前窗口宽度,得到该宽度下的相应FONT-SIZE值
    var rem = wH * whdef;// 以默认比例值乘以当前窗口宽度,得到该宽度下的相应FONT-SIZE值
    $('html').css('font-size', rem + "px");

    // 创建地图
    initMap();

    // 行政区划边框
    getBoundary();

    // 添加标记点
    findInfo();
}) ;


/**
 * 地图添加标记点
 */
function findInfo(){
    addComplexOverlay(map,new BMap.Point(108.65836,19.100888),"images/g32.ico",1,"");
    addComplexOverlay(map,new BMap.Point(108.672964,19.113256),"images/d32.ico",2,"");
    addComplexOverlay(map,new BMap.Point(108.899457,19.024294),"images/d32.ico",3,"");
    addComplexOverlay(map,new BMap.Point(108.734456,19.215571),"images/d32.ico",4,"");
    addComplexOverlay(map,new BMap.Point(109.08113,18.916535),"images/d32.ico",5,"");
    addComplexOverlay(map,new BMap.Point(108.995899,18.903402),"images/d32.ico",6,"");
    addComplexOverlay(map,new BMap.Point(108.683863,19.23414),"images/d32.ico",7,"");
    addComplexOverlay(map,new BMap.Point(108.94545,18.879322),"images/d32.ico",8,"");
    addComplexOverlay(map,new BMap.Point(108.730431,19.065301),"images/d32.ico",9,"");
    addComplexOverlay(map,new BMap.Point(108.762627,18.999138),"images/d32.ico",10,"");

    addComplexOverlay(map,new BMap.Point(108.875885,19.036871),"images/d32.ico",11,"");
    addComplexOverlay(map,new BMap.Point(108.832766,18.957568),"images/d32.ico",12,"");
    addComplexOverlay(map,new BMap.Point(108.872436,19.119414),"images/d32.ico",13,"");
    addComplexOverlay(map,new BMap.Point(108.80747,19.141273),"images/d32.ico",14,"");
    addComplexOverlay(map,new BMap.Point(108.862087,19.2467),"images/d32.ico",15,"");
    addComplexOverlay(map,new BMap.Point(108.909805,18.811442),"images/d32.ico",16,"");
    addComplexOverlay(map,new BMap.Point(108.694787,18.799944),"images/d32.ico",17,"");
    addComplexOverlay(map,new BMap.Point(108.764783,18.884795),"images/d32.ico",18,"");
    addComplexOverlay(map,new BMap.Point(108.957954,19.095913),"images/d32.ico",19,"");
    addComplexOverlay(map,new BMap.Point(108.786629,18.805967),"images/d32.ico",20,"");
}

//查询数据
function  searchDate(){
    //清除地图所有覆盖物
    map.clearOverlays();
    getBoundary();
}

//加载行政区划边框
function getBoundary(){
    var bdary = new BMap.Boundary();
    bdary.get("海南省东方市", function(rs){       //获取行政区域
//			map.clearOverlays();        //清除地图覆盖物
        var count = rs.boundaries.length; //行政区域的点有多少个
        if (count === 0) {
            alert('未能获取当前输入行政区域');
            return ;
        }
        var pointArray = [];
        for (var i = 0; i < count; i++) {
            var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 3, strokeColor: "#FFD700",fillColor:"none"}); //建立多边形覆盖物
            pay1=ply;
            map.addOverlay(ply);  //添加覆盖物
            pointArray = pointArray.concat(ply.getPath());
        }
    });
}

function initMap() {
    // 东方市人民政府坐标：108.65836,19.100888
    map = bmap('map' , new BMap.Point(108.891264,19.049446), 12,false,false,false);// new BMap.Map("container");    // 创建Map实例
    //地图自定义样式
    map.setMapStyle({
        styleJson: [
            {
                "featureType": "land",
                "elementType": "geometry.fill",
                "stylers": {
                    "color": "#20254c",
                    "hue": "#20254c",
                    "visibility": "on"
                }
            },
            {
                "featureType": "water",
                "elementType": "geometry.fill",
                "stylers": {
                    "color": "#2e5eb0"
                }
            },
            {
                "featureType": "green",
                "elementType": "geometry.fill",
                "stylers": {
                    "color": "#079f3a"
                }
            },
            {
                "featureType": "road",
                "elementType": "all",
                "stylers": {
                    "color": "#1892dd"
                }
            },
            {
                "featureType": "all",
                "elementType": "labels.text.fill",
                "stylers": {
                    "color": "#857f7f"
                }
            },
            {
                "featureType": "all",
                "elementType": "labels.text.stroke",
                "stylers": {
                    "color": "#182c5f"
                }
            },
            {
                "featureType": "poi",
                "elementType": "all",
                "stylers": {
                    "visibility": "off"
                }
            },
            {
                "featureType": "all",
                "elementType": "labels.icon",
                "stylers": {
                    "visibility": "off"
                }
            },
            {
                "featureType": "all",
                "elementType": "labels.text.fill",
                "stylers": {
                    "color": "#2da0c6",
                    "visibility": "on"
                }
            },  {
                "featureType": "manmade",
                "elementType": "geometry.fill",
                "stylers": {
                    "color": "#6a6666ff"
                }
            }
            ,  {
                "featureType": "building",
                "elementType": "geometry.fill",
                "stylers": {
                    "color": "#857f7fff"
                }
            }
        ]
    });


}

